package com.haixue.android.academy.activity;

import android.academy.haixue.com.haixue.R;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.EditText;

import com.haixue.android.academy.view.InputMethodRelativeLayout;

import butterknife.InjectView;
import butterknife.OnClick;
import cn.woblog.android.common.utils.ToastAlone;

public class LoginActivity extends BaseLoginActivity implements InputMethodRelativeLayout.OnSizeChangedListenner{
    @InjectView(R.id.editText_user_name)
    EditText editText_user_name;

    @InjectView(R.id.editText_user_password)
    EditText editText_user_password;
    private InputMethodRelativeLayout inputMethodRelativeLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
    }

    @Override
    protected void initViews() {
        super.initViews();
        inputMethodRelativeLayout = (InputMethodRelativeLayout) findViewById(R.id.inputMethodRelativeLayout);
    }

    @Override
    protected void initListener() {
        super.initListener();
        inputMethodRelativeLayout.setOnSizeChangedListenner(this);
    }

    @OnClick(R.id.button_login)
    public void processLogin() {
        String username = editText_user_name.getText().toString().trim();
        String password = editText_user_password.getText().toString().trim();
        if (TextUtils.isEmpty(username)){
            ToastAlone.showSortToast(this, R.string.login_hint_user_name);
            return;
        }
        if (TextUtils.isEmpty(password)){
            ToastAlone.showSortToast(this, R.string.login_hint_password);
            return;
        }
        super.doLogin(username,password);
    }
    @OnClick(R.id.ib_delete)
    public void clearUsername() {
        editText_user_name.setText("");
    }

    @Override
    public void onSizeChange(boolean paramBoolean, int w, int h) {
        log.debug("onSizeChange "+paramBoolean+",w:"+w+",h:"+h);
        if (paramBoolean) {
            inputMethodRelativeLayout.setPadding(0, -(h / 2), 0, 0);
        } else {
            inputMethodRelativeLayout.setPadding(0, 0, 0, 0);
        }
    }
}
